package backend.service.admin;

import backend.model.admin.Occupation;
import backend.service.base.DBModelServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OccupationServiceImpl extends DBModelServiceImpl<Occupation> implements OccupationService {

    @Override
    public Class<Occupation> getEntityClass() {
        return Occupation.class;
    }

    @Override
    public List<Occupation> findAllOccupations() {
        return dbModelDao.findByNamedQuery("findAllOccupations");
    }

    @Override
    public List<Occupation> findAllActiveOccupations() {
        return dbModelDao.findByNamedQuery("findAllActiveOccupations");
    }

    @Override
    public Occupation findOccupationByName(String name) {
        List<Occupation> occupationsByName = dbModelDao.findByNamedQueryAndParams("findOccupationByName", new String[]{"name"}, new Object[]{name});
        assert occupationsByName.size() <= 1;
        if (occupationsByName.size() == 1) {
            return occupationsByName.get(0);
        }
        return null;
    }
}
